<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="eBrain.beans.Item"%>
<%@page import="eBrain.beans.Bid"%>
<%@page import="eBrain.beans.User"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Date"%>
<jsp:useBean id="dataManager" scope="application"
  class="eBrain.model.DataManager"/>
  
<%String base = (String)application.getAttribute("base"); %>
   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="/eBrain/css/eshop.css" type="text/css"/>
</head>
<body>
<jsp:include page="TopMenu.jsp" flush="true"/>
<jsp:include page="LeftMenu.jsp" flush="true"/>
<div class="content">
<% 	
		Item item = (Item)session.getAttribute("itemInfo");		
		%>
    	<table>
        <tr>
          <td>Name:</td>
          <td>
              <%=item.getName().trim()%>
          </td>
        </tr>
        <tr>
          <td>Start:</td>
          <td>
            <%=item.getStart().toGMTString()%>
          </td>
        </tr>
        <tr>
          <td>Ende:</td>
          <td>
            <%=item.getEnd().toGMTString()%>
          </td>
        </tr>
        <tr>
          <td>Higest Bid:</td>	
          <td>
             
             <%Bid tempBid = dataManager.getNextToLast(item.getId());
            		if(tempBid.isEmpty()){
            		out.println(item.getStartBid());
            		}
            		else{
            		out.println(tempBid.getBidValue()+0.5);
            		}
            		%>
          </td>
        </tr>
       
          
      </table>
    
     <div>  
     	<font color="red">
      			<%	String msg = (String)request.getAttribute("msg");
      				if(msg!=null){
     					out.print(msg);
      				} %>
   		 </font>
    </div>
    
    <%
    User user = (User)session.getAttribute("validUser");
    if((item.getEnd().getTime()>(System.currentTimeMillis()))&&!(item.getUserid()==user.getUser_id())){ 
   %>
  
    	
    <a class="mebutton" href="<%=base%>?action=bid">Bieten</a>
    <%}%>
    <%
        ArrayList bids = (ArrayList)dataManager.getBidsForItem(item.getId());
        Iterator iterator = bids.iterator();
        if(!bids.isEmpty()){
          
  %>
    
    <p>Bids: <strong></strong></p>
      <table>
        <tr>
          <th>Bid Value</th>
          <th>User</th>
          <th>Timestamp</th>
          
          </tr>
          <%while (iterator.hasNext()) {
          Bid bid = (Bid)iterator.next(); %>
          <tr>
            <td><%=bid.getBidValue()%></td>
            <td><%=dataManager.getUsernameByUserId(bid.getUserId())%></td>
            <td><%=bid.getTimestamp().toString()%></td>
            
            </tr>
<%
          }
          }
          else{
  %>
  		<p>No bids for this item. <strong></strong></p>
  <%
  	} %>
        </table>
    </div>
 
</body>
</html>